<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            height: 400px;
            background-color: #f00;
            position: relative;
            margin: 50px auto;
        }
        .box span {
            width: 100px;
            height: 100px;
            background-color: #000;
            position: absolute;

            /* 让元素拒绝事件 */
            pointer-events: none;
        }

        .box span:hover {
            background-color: #ff0 !important;
        }
    </style>
</head>
<body>

    <div class="box">
        <span></span>
    </div>

    <script>

        // offsetX   距离目标源的坐标

        var oBox = document.querySelector('.box') ;
        var oSpan = document.querySelector('span') ;

       
        document.onmousemove = function(e) {
            var x = e.offsetX - 50 ;
            var y = e.offsetY - 50 ;

            oSpan.style.cssText = `left:${x}px;top:${y}px;`
        }
       
        


        // oSpan.onclick = function() {
        //     alert(666)
        // }
            

    </script>
    
</body>
</html>